import React, { Component } from 'react';
import '../assets/style/rent_out.less';

import { SearchBar, WhiteSpace } from 'antd-mobile';
import Select from '../components/picker'
import Card from '../components/card'
import { showMes } from '../api/url';
import api from '../api/index'
import axios from 'axios'
import provincial from '../Provincial.json'
export default class one extends Component {
    constructor(props) {
        super(props);
        this.state = { value: '', data: [] ,
        res: [],
        colourlist: [
            { backgroundColor: '#FFEBEF', color: 'red' },
            { backgroundColor: '#E8EAF6', color: '#6978D5' },
            { backgroundColor: '#E0F7FA', color: '#51995B' },
            { backgroundColor: '#E0F8FA', color: '#579CA5' }
        ],
        sValue: [],
        priceValue: [],
        genreValue: [],
        area: '',
        price: [
            {
                label: '1000-10000',
                value: '1000-10000',
            },
            {
                label: '10001-30000',
                value: '10001-30000',
            },
            {
                label: '30001-60000',
                value: '10001-60000',
            },
            {
                label: '60001-120000',
                value: '60001-120000',
            },
            {
                label: '120001-500000',
                value: '120000-500000',
            },
        ],
        data1: [
            {
                label: '厅室',
                value: '厅室',
            },
            {
                label: '别墅',
                value: '别墅',
            },
            {
                label: '小别墅',
                value: '小别墅',
            },
        ]
    
    
    };
    }

    async componentDidMount() {
        await api.get(showMes.showAll).then(e => {
            this.setState({
                data: e.data.data
            })
        })
        console.log(19, this.state.data)
        let citydata = provincial.Location.CountryRegion[0].State
        let regindata = []
        citydata.forEach(item => {
            let obj = {}
            obj.label = item['-Name']
            obj.value = item['-Name']
            if (item.City) {
                let children = []
                item.City.forEach(element => {
                    let obj1 = {}
                    obj1.label = element['-Name']
                    obj1.value = element['-Name']
                    if (element['Region']) {
                        let children1 = []
                        if (Array.isArray(element['Region'])) {
                            element['Region'].forEach(item1 => {
                                let obj2 = {}
                                obj2.label = item1['-Name']
                                obj2.value = item1['-Name']
                                children1.push(obj2)
                            })
                            obj1.children = children1
                        } else {
                            let obj2 = {}
                            obj2.label = element['Region']['-Name']
                            obj2.value = element['Region']['-Name']
                            children1.push(obj2)
                            obj1.children = children1
                        }
                    }
                    children.push(obj1)
                });
                obj.children = children
            }
            regindata.push(obj)
        })
        this.setState({
            area: regindata
        })
    }
    async getareaChildrenMsg(e) {
        console.log(e, '接收子传过来的区域参数')
        await this.setState({ sValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }

        let res = await axios.post('/used/secondTypeFindAll', data)
        this.setState({
            res: res.data.data
        }
        )
    }
    async getpriceChildrenMsg(e) {
        console.log(e, '接收子传过来的价格参数')
        await this.setState({ priceValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }
        let res = await axios.post('/used/secondTypeFindAll', data)

        this.setState({
            res: res.data.data
        }
        )
    }
    async getChildrenMsg(e) {
        console.log(e, '接收子传过来的类型参数')
        await this.setState({ genreValue: e })
        let data = {
            area: this.state.sValue,
            price: this.state.priceValue,
            type: this.state.genreValue
        }
        let res = await axios.post('/used/secondTypeFindAll', data)
        this.setState({
            res: res.data.data
        }
        )
    }
    onChange = (value) => {
        this.setState({ value });
    };
    clear = () => {
        this.setState({ value: '' });
    };
    onSubmit = (value) => {
        console.log('确认的值', value)
    }

    render() {
        return (
            <div style={{ width: '100%', height: '600px', overflow: 'hidden' }}>
                <WhiteSpace />
                <SearchBar
                    defaultValue='3213212'
                    value={this.state.value}
                    placeholder="输入楼盘名或地址"
                    onSubmit={this.onSubmit}
                    onChange={this.onChange}
                />
                <  Select parent={this} />
                {
                    this.state.data.map((data) => <Card data={data} href='/details' id={data.id} />)
                }
            </div>
        )
    }
}
